package com.rockcent.mall;

import com.rockcent.common.common.RWebMvcConfigurerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

import java.util.Arrays;

/**
 * Created by oyhk on 15-2-15.
 */
@Configuration
@EnableWebMvc
public class WebMvcConfig extends RWebMvcConfigurerAdapter {

    @Autowired
    private AuthInterceptor authInterceptor;
    @Autowired
    private UserPermissionInterceptor userPermissionInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);
        registry.addInterceptor(authInterceptor).addPathPatterns(
                Arrays.asList(
                        "/monitor/telnet/info",
                        "/market/merchant/**",
                        "/merchant/**",
                        "/mall/**",
                        "/mall/category/**",
                        "/upload/**"
                ).toArray(new String[]{}))
                .excludePathPatterns(
                "/monitor/telnet/info"
        );

        // 权限拦截器
        registry.addInterceptor(userPermissionInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/mall/member_info")
                .excludePathPatterns("/location/info");
    }
}
